//查询方式
function getSelect() {
    var radios = document.getElementsByName('selecttype');
    var selectvalue = null; //  selectvalue为radio中选中的值
    for (var i = 0; i < radios.length; i++) {
        if (radios[i].checked == true) {
            selectvalue = radios[i].value;
            break;
        }
    }
    console.log(selectvalue);
    return selectvalue;
}

//输入框内容
function getInputInfo() {
    var id = $('#gonghao').val();
    var name = $('#xingming').val();
    var sex = $('#xingbie').val();
    var pwd = $('#mima').val();
    var age = $('#nianlin').val();
    var birthday = $('#shengri').val();
    var arr = [id, name, sex, pwd, age, birthday];
    console.log(id, name, sex, pwd, age, birthday);
    return arr;
}

//添加按钮
$('#add').click(function() {
    console.log('选择添加')
});

//删除按钮
$('#del').click(function() {
    console.log('选择删除');
    $(".ischeck").each(function() {
        var statu = $(this).is(':checked');
        if (statu) {
            $(this).parent().parent().remove();
        }
    });
});

//编辑按钮
$('#update').click(function() {
    console.log('选择编辑')
});

//查询按钮
$('#select').click(function() {
    var fun = getSelect();
    console.log('选择查询')
    if (fun == 'id') {
        $('#xingming1').attr('disabled', 'true');
    } else if (fun == 'name') {
        $('#gonghao1').attr('disabled', 'true');
    }
});

//确定按钮
$('#addAll').click(function() {
    var info = getInputInfo();
    console.log('确定');
    var newtr = $('<tr> <td> <input type = "checkbox" class="ischeck" > </td> <td class="gh" id="' + info[0] + '">' + info[0] + '</td><td name="' + info[1] + '">' + info[1] + '</td><td>' + info[2] + '</td><td>' + info[3] + '</td><td>' + info[4] + '</td><td>' + info[5] + '</td></tr>');
    $('#mytbody').append(newtr);
    //清空内容
    $('#gonghao').val('');
    $('#xingming').val('');
    $('#xingbie').val('');
    $('#mima').val('');
    $('#nianlin').val('');
    $('#shengri').val('');
});

//查询框的按钮重置状态
$('#over,#selectAll,#cent').click(function() {
    $('#gonghao1').removeAttr("disabled");
    $('#xingming1').removeAttr("disabled");
});

$('#over1,#resultAll,#cent1').click(function() {
    $('#retbody').empty();
});

//确定查询
$('#selectAll').click(function() {
    var fun = getSelect();
    if (fun == 'id') {
        var id = $('#gonghao1').val();
        // alert($("#" + id).parent().html());
        var m = $("#" + id).parent().html();
        console.log($("#" + id).parent().text());
        $('#retbody').append(m);
        // alert($(".gh,[id=" + "'" + id + "'" + "]").parent().html());
        $('#gonghao1').val('');
    } else if (fun == 'name') {
        var xingming = $('#xingming1').val();
        // alert($("[name=" + "'" + xingming + "'" + "]").parent().html());
        var n = $("[name=" + "'" + xingming + "'" + "]").parent().html();
        console.log($("[name=" + "'" + xingming + "'" + "]").parent().text());
        $('#retbody').append(n);
        $('#xingming1').val('');
    }
});

//确定编辑
$('#upAll').click(function() {
    var upid = $('#upgonghao').val();
    var upname = $('#upxingming').val();
    var upsex = $('#upxingbie').val();
    var uppwd = $('#upmima').val();
    var upage = $('#upnianlin').val();
    var upbirthday = $('#upshengri').val();
    var info = [upid, upname, upsex, uppwd, upage, upbirthday];
    var uptr = $('<tr> <td> <input type = "checkbox" class="ischeck" > </td> <td class="gh" id="' + info[0] + '">' + info[0] + '</td><td name="' + info[1] + '">' + info[1] + '</td><td>' + info[2] + '</td><td>' + info[3] + '</td><td>' + info[4] + '</td><td>' + info[5] + '</td></tr>');
    //获取被选中的那条数据
    $(".ischeck").each(function() {
        var upstatu = $(this).is(':checked');
        if (upstatu) {
            $(this).parent().parent().replaceWith(uptr);
        }
    });
});